package cron

import (
	"context"

	"code.bydev.io/frameworks/byone/core/logc"
	"github.com/spf13/cast"
)

const (
	KeyApproveStartID          = "kyc:admin:approved:start_id"
	KeyOnfidoCompensateStartID = "kyc:admin:onfido:compensate:start_id"
	KeySelfieCompensateScanner = "kyc:admin:selfie:compensate:scanner"
)

func (d *Domain) GetScannerStartID(ctx context.Context, scannerKey string) (int64, error) {
	startID, err := d.redisClient.GetCtx(ctx, scannerKey)
	if err != nil {
		logc.Errorw(ctx, "s.redisClient.GetCtx error", logc.Field("err", err))
		return 0, err
	}
	return cast.ToInt64(startID), nil
}

func (d *Domain) SetScannerStartID(ctx context.Context, scannerKey string, newStartID int64) error {
	err := d.redisClient.SetCtx(ctx, scannerKey, cast.ToString(newStartID))
	if err != nil {
		logc.Errorw(ctx, "s.redisClient.SetCtx error", logc.Field("err", err))
		return err
	}
	logc.Infow(ctx, "s.SetScannerStartID", logc.Field("scannerKey", scannerKey), logc.Field("newStartID", newStartID))
	return nil
}
